package com.kaifamiao.www.demo.Do30;

import java.util.Arrays;
import java.util.Scanner;

public class Bank {
    private Scanner sc = new Scanner(System.in);
    //设置数组存账户信息
    private Account[] accounts = new Account[10];
    //记录已有多少账户
    private int count = 0;
    //当前登录用户
    private Account current;

    /**
     * 系统入口
     */
    public void start(){
        System.out.println("欢迎来到开发银行");
        //测试，存满账户
//        for (int i = 0;i<10;i++){
//            accounts[i] = new Account();
//            count++;
//        }
        firstMenu();
//        while(true){
//            menu();
//        }

    }

    /**
     * 一级菜单
     */
    public void firstMenu(){
        System.out.println("请选择要办理的业务，（输入对应的编号）");
        System.out.println("1，开户");
        System.out.println("2，登录");
        System.out.println("0，退出");
        //用户输入要执行的功能
        int selector = sc.nextInt();
        selectFirstMenu(selector);
    }

    private void selectFirstMenu(int selector){
        switch (selector){
            case 1:
                creat();
                break;
            case 2:
                login();
                break;
            case 0:
                exit();
                break;
        }
    }

    private void login() {
        System.out.println("请输入卡号");
        String cardID = sc.next();
        System.out.println("请输入密码");
        String passWard = sc.next();
    }

    /**
     *
     */
    private void findAccunt(String cardID,String passWard){


    }
    //设置菜单
    private void menu(){
        System.out.println("请选择要办理的业务，（输入对应的编号）");
        System.out.println("1，开户");
        System.out.println("2，存钱");
        System.out.println("3，取钱");
        System.out.println("4，查询余额");
        System.out.println("5，查询账户信息");
        System.out.println("6，转账");
        System.out.println("7，查看所有账户信息");//为了自己方便
        //用户输入要执行的功能
        int selector = sc.nextInt();
        selectMenu(selector);
    }
    /**
     * 根据用户的输入选择要执行的功能
     */
    private void selectMenu(int selector){
        switch (selector){
            case 1:
                creat();//开户
                break;
            case 2:
                saveMoney();//存钱
                break;
            case 3:
                takeMoney();//取钱
                break;
            case 4:
                getMoney();//查询余额
                break;
            case 5:
                showAccount();//查询账户信息
                break;
            case 6:
                transfer();//转账
                break;
            case 7:
                showAll();//查看所以账户信息
                break;
            case 0:
                exit();//退出
                break;

        }
    }
    /**
     * 退出
     */
    private void exit(){
        System.out.println("欢迎下次光临");
        System.exit(0);//虚拟机停止
    }
    /**
     * 开户
     */
    private void creat(){
        Account account = new Account();
        System.out.println("请输入开户人姓名：");
        String  name = sc.next();
        System.out.println("请输入开户密码");
        String password = sc.next();
        //生成卡号
        long cardID = System.currentTimeMillis();
        account.setName(name);
        account.setPassward(password);
        account.setCardID(cardID);
        //将创建的账户存到数组中
        //判断数组还有空间吗？已有账户数量等于最大账户数量  扩容
        if(count == accounts.length){
            int newSize = accounts.length*2;
            accounts = Arrays.copyOf(accounts,newSize);
        }
        accounts[count] = account;
        count++;//人数加一
        System.out.println("您的卡号是"+cardID);

    }

    /**
     * 查看所有账户信息
     */
    private void showAll(){
        if(count >0){
            System.err.println("现有"+count+"个账户");
            for(int i =0;i<count;i++){
                accounts[i].show();
            }
        }else{
            System.out.println("还没有客户");
        }

    }
    /**
     * 存钱
     */
    private void saveMoney(){

    }
    /**
     * 取钱
     */
    private void takeMoney(){

    }
    /**
     * 查询余额
     */
    private void getMoney(){

    }
    /**
     * 展示账户信息
     */
    private void showAccount(){

    }
    /**
     * 转账
     */
    private void transfer(){

    }

}
